class Admin::ArticlesController < Admin::BaseController
  
  def index
    @title = "所有文章"
    @articles = Article.paginate :page => params[:page], :per_page => 15
  end

  def new
    @title = "新文章"
    @article = Article.new
  end

  def create
    @article = Article.new(params[:article])
    @article.user = @current_user
    if @article.save
      redirect_to admin_articles_path
    else
      render :new
    end
  end

  def edit
    @article = Article.find params[:id]
    @title = "编辑文章"
    render :new
  end

  def update
    @article = Article.find params[:id]
    if @article.update_attributes(params[:article])
      flash[:notice] = "更新成功!"
      redirect_to :back
    else
      render :new
    end
  end

  def show
    
  end

  def destroy
    @article = Article.find params[:id]
    if @article.destroy
      redirect_to admin_articles_path
    else
      redirect_back
    end
  end

  def category
    @title = "文章分类"
    @category = Category.new
    @categories = Category.get_categories(Article).paginate :page => params[:page], :per_page => 15
  end

  def create_category
    @category = Category.new(params[:category])
    @category.object_type = "Article"

    if @category.save
      redirect_to category_admin_articles_path
    else
      render :category
    end
  end

end
